var _o140;
var cc__decorate = __decorate;
var cc__awaiter = __awaiter;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GlobalTili = require("GlobalTili");
var $2NodeManager = require("NodeManager");
var $2WorldNodeMgr = require("WorldNodeMgr");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_ccUtil = _o140 = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
  }
  return babel_createClass(_ctor, null, [{
    key: "getChildByName",
    value: function getChildByName(e, t) {
      for (var _n79 = 0; _n79 < e.childrenCount; _n79++) {
        if (e.children[_n79].name == t) {
          return e.children[_n79];
        }
        if (e.children[_n79].childrenCount > 0) {
          var _i36 = _o140.getChildByName(e.children[_n79], t);
          if (_i36) {
            return _i36;
          }
        }
      }
    }
  }, {
    key: "pauseAllActions",
    value: function pauseAllActions(e) {
      for (var _t79 = 0; _t79 < e.childrenCount; _t79++) {
        if (0 == e.children[_t79].childrenCount && e.children[_t79].activeInHierarchy) {
          console.log(e.children[_t79].name);
          e.children[_t79].pauseAllActions();
        } else {
          this.pauseAllActions(e.children[_t79]);
        }
      }
    }
  }, {
    key: "resumeAllActions",
    value: function resumeAllActions(e) {
      for (var _t80 = 0; _t80 < e.childrenCount; _t80++) {
        if (0 == e.children[_t80].childrenCount && e.children[_t80].activeInHierarchy) {
          e.children[_t80].resumeAllActions();
        } else {
          this.resumeAllActions(e.children[_t80]);
        }
      }
    }
  }, {
    key: "zhendong",
    value: function zhendong(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : .1;
      cc.tween(e).to(t, {
        position: cc.v3(0, 10)
      }).to(t, {
        position: cc.v3(0, -10)
      }).to(t, {
        position: cc.v3(5, 10)
      }).to(t, {
        position: cc.v3(-5, -10)
      }).to(t, {
        position: cc.v3(0, 10)
      }).to(t, {
        position: cc.v3(0, 0)
      }).start();
    }
  }, {
    key: "addCompment",
    value: function addCompment(e, t) {
      var n = e.getComponent(t);
      n || (n = e.addComponent(t));
      return n;
    }
  }, {
    key: "scaleline",
    value: function scaleline(e, t, n) {
      var _o141 = e.add(t).scale(cc.v2(.5, .5));
      return {
        posA: e = e.add(e.sub(_o141).scale(cc.v2(.5 * n, .5 * n))),
        posB: t = t.add(t.sub(_o141).scale(cc.v2(.5 * n, .5 * n)))
      };
    }
  }, {
    key: "scalelineRound",
    value: function scalelineRound(e, t, n) {
      var _o142 = this.scaleline(e, t, n);
      _o142.posA.x = Math.round(_o142.posA.x);
      _o142.posA.y = Math.round(_o142.posA.y);
      _o142.posB.x = Math.round(_o142.posB.x);
      _o142.posB.y = Math.round(_o142.posB.y);
      return _o142;
    }
  }, {
    key: "setChildrenViseble",
    value: function setChildrenViseble(e, t) {
      var _iterator8 = babel_createForOfIteratorHelper(e.children);
      var _step8;
      try {
        for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
          var _n80 = _step8.value;
          _n80.active = t;
        }
      } catch (err) {
        _iterator8.e(err);
      } finally {
        _iterator8.f();
      }
    }
  }, {
    key: "getTargetAngel",
    value: function getTargetAngel(e) {
      this._temppos1.x = e.x;
      this._temppos1.y = e.y;
      return 180 * this._temppos.signAngle(this._temppos1) / Math.PI;
    }
  }, {
    key: "AngleBetween",
    value: function AngleBetween(e) {
      this._temppos1.x = e.x;
      this._temppos1.y = e.y;
      return this._temppos1.signAngle(cc.v2(1, 0));
    }
  }, {
    key: "AngleBetweenTwoPoints",
    value: function AngleBetweenTwoPoints(e, t) {
      var n = cc.v2(e.x - t.x, e.y - t.y);
      return this.AngleBetween(n);
    }
  }, {
    key: "Angle2Vec2",
    value: function Angle2Vec2(e) {
      var t = cc.misc.degreesToRadians(e + 90);
      return cc.v2(Math.sin(t), -Math.cos(t));
    }
  }, {
    key: "checkWorldBox",
    value: function checkWorldBox(e, t) {
      var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var _o143 = this.getworldbox(e);
      var i = this.getworldbox(t);
      this._intersecRect.x = this._intersecRect.y = this._intersecRect.width = this._intersecRect.height = 0;
      _o143.intersection(this._intersecRect, i);
      if (this._intersecRect.width <= 0 || this._intersecRect.height <= 0) {
        return false;
      }
      var s = Math.min(_o143.width * _o143.height, i.width * i.height);
      return this._intersecRect.width * this._intersecRect.height / s > n;
    }
  }, {
    key: "checkStaticWorldBox",
    value: function checkStaticWorldBox(e, t) {
      var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var _o144 = this.getStaticWorldbox(e);
      var i = this.getStaticWorldbox(t);
      this._intersecRect.x = this._intersecRect.y = this._intersecRect.width = this._intersecRect.height = 0;
      _o144.intersection(this._intersecRect, i);
      if (this._intersecRect.width <= 0 || this._intersecRect.height <= 0) {
        return false;
      }
      var s = Math.min(_o144.width * _o144.height, i.width * i.height);
      return this._intersecRect.width * this._intersecRect.height / s > n;
    }
  }, {
    key: "getStaticWorldbox",
    value: function getStaticWorldbox(e) {
      if (!e._mrect) {
        var _t81 = e.width;
        var _n81 = e.height;
        var _o145 = cc.rect(-e.anchorX * _t81, -e.anchorY * _n81, _t81, _n81);
        e._calculWorldMatrix();
        _o145.transformMat4(_o145, e._worldMatrix);
        e._mrect = _o145;
      }
      return e._mrect;
    }
  }, {
    key: "getPolygon",
    value: function getPolygon(e, t) {
      var n = -e.width * e.anchorX;
      var _o146 = e.width * (1 - e.anchorX);
      var i = e.height * (1 - e.anchorY);
      var s = -e.height * e.anchorY;
      var a = [];
      if (t) {
        a.push(t.convertToNodeSpaceAR(e.convertToWorldSpaceAR(cc.v2(n, i))));
        a.push(t.convertToNodeSpaceAR(e.convertToWorldSpaceAR(cc.v2(_o146, i))));
        a.push(t.convertToNodeSpaceAR(e.convertToWorldSpaceAR(cc.v2(_o146, s))));
        a.push(t.convertToNodeSpaceAR(e.convertToWorldSpaceAR(cc.v2(n, s))));
      } else {
        a.push(e.convertToWorldSpaceAR(cc.v2(n, i)));
        a.push(e.convertToWorldSpaceAR(cc.v2(_o146, i)));
        a.push(e.convertToWorldSpaceAR(cc.v2(_o146, s)));
        a.push(e.convertToWorldSpaceAR(cc.v2(n, s)));
      }
      return a;
    }
  }, {
    key: "getdestance",
    value: function getdestance(e, t) {
      return e.convertToWorldSpaceAR(cc.Vec2.ZERO).sub(t.convertToWorldSpaceAR(cc.Vec2.ZERO)).mag();
    }
  }, {
    key: "getworldbox",
    value: function getworldbox(e) {
      var t = e.width;
      var n = e.height;
      var _o147 = cc.rect(-e.anchorX * t, -e.anchorY * n, t, n);
      e._calculWorldMatrix();
      _o147.transformMat4(_o147, e._worldMatrix);
      return _o147;
    }
  }, {
    key: "addchild",
    value: function addchild(e, t) {
      if (e.parent == t) {
        return;
      }
      var n = this.convertNodepos(e, t);
      e.setParent(t);
      e.setPosition(n);
      return e;
    }
  }, {
    key: "convertNodepos",
    value: function convertNodepos(e, t) {
      var n = e.convertToWorldSpaceAR(cc.Vec2.ZERO);
      return t.convertToNodeSpaceAR(n);
    }
  }, {
    key: "lineIntersect",
    value: function lineIntersect(e, t, n, _o148) {
      var i = t.y - e.y;
      var s = e.x - t.x;
      var a = i * e.x + s * e.y;
      var r = _o148.y - n.y;
      var l = n.x - _o148.x;
      var c = r * n.x + l * n.y;
      var d = i * l - r * s;
      if (0 == d) {
        return false;
      }
      {
        var _h3 = (l * a - s * c) / d;
        var u = (i * c - r * a) / d;
        if ((this.isInBetween(e.x, _h3, t.x) || this.isInBetween(e.y, u, t.y)) && (this.isInBetween(n.x, _h3, _o148.x) || this.isInBetween(n.y, u, _o148.y))) {
          return true;
        }
      }
      return false;
    }
  }, {
    key: "isInBetween",
    value: function isInBetween(e, t, n) {
      return !(Math.abs(e - t) < 1e-6 || Math.abs(t - n) < 1e-6) && (e < t && t < n || n < t && t < e);
    }
  }, {
    key: "InRandAngleBetweenTwoPoints",
    value: function InRandAngleBetweenTwoPoints(e, t, n, i) {
      var s = _o140.AngleBetweenTwoPoints(e, t);
      return s > Math.min(n, i) && s < Math.max(n, i);
    }
  }, {
    key: "InRandAngle",
    value: function InRandAngle(e, t, n) {
      var i = _o140.AngleBetween(e);
      return i > Math.min(t, n) && i < Math.max(t, n);
    }
  }, {
    key: "convertToWXRect",
    value: function convertToWXRect(e) {
      var t = {};
      if (!window.wx) {
        return t;
      }
      var n = window.canvas.width / cc.winSize.width;
      var _o149 = window.canvas.height / cc.winSize.height;
      var i = e.convertToWorldSpaceAR(cc.v2(0, 0));
      console.log("worldpos", i);
      var s = e.width * n / (window.canvas.width / wx.getSystemInfoSync().windowWidth);
      var a = e.height * _o149 / (window.canvas.height / wx.getSystemInfoSync().windowHeight);
      var r = wx.getSystemInfoSync().windowWidth / (cc.winSize.width / i.x) - s / 2;
      var l = wx.getSystemInfoSync().windowHeight / (cc.winSize.height / (cc.winSize.height - i.y)) - a / 2;
      t.left = r;
      t.top = l;
      t.width = s;
      t.height = a;
      return t;
    }
  }, {
    key: "isInPolygon",
    value: function isInPolygon(e, t) {
      var n;
      var _o150;
      var i;
      var s;
      var a = 0;
      var r = t.length;
      i = t[0];
      for (n = 1; n <= r; n++) {
        s = t[n % r];
        if (e.x > Math.min(i.x, s.x) && e.x <= Math.max(i.x, s.x) && e.y <= Math.max(i.y, s.y) && i.x != s.x) {
          _o150 = (e.x - i.x) * (s.y - i.y) / (s.x - i.x) + i.y;
          (i.y == s.y || e.y <= _o150) && a++;
        }
        i = s;
      }
      return a % 2 != 0;
    }
  }, {
    key: "computeUv",
    value: function computeUv(e, t, n) {
      var _o151 = [];
      var _iterator9 = babel_createForOfIteratorHelper(e);
      var _step9;
      try {
        for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
          var _i37 = _step9.value;
          var _e92 = this.clamp(0, 1, (_i37.x + t / 2) / t);
          var _s14 = this.clamp(0, 1, 1 - (_i37.y + n / 2) / n);
          _o151.push(cc.v2(_e92, _s14));
        }
      } catch (err) {
        _iterator9.e(err);
      } finally {
        _iterator9.f();
      }
      return _o151;
    }
  }, {
    key: "clamp",
    value: function clamp(e, t, n) {
      if (e > t) {
        var _n82 = e;
        e = t;
        t = _n82;
      }
      if (n < e) {
        return e;
      } else {
        if (n > t) {
          return t;
        } else {
          return n;
        }
      }
    }
  }, {
    key: "splitPolygonByTriangle",
    value: function splitPolygonByTriangle(e) {
      if (e.length <= 3) {
        return [0, 1, 2];
      }
      var t = {};
      for (var _s15 = 0; _s15 < e.length; _s15++) {
        var _n83 = e[_s15];
        t["".concat(_n83.x, "-").concat(_n83.y)] = _s15;
      }
      var n = function n(e) {
        return t["".concat(e.x, "-").concat(e.y)];
      };
      e = e.concat([]);
      var _o152 = [];
      var i = 0;
      for (; e.length > 3;) {
        var _t82 = e[i % e.length];
        var _s16 = e[(i + 1) % e.length];
        var _a24 = e[(i + 2) % e.length];
        var _r6 = (i + 1) % e.length;
        var _l5 = _s16.sub(_t82);
        var _c4 = _a24.sub(_s16);
        if (_l5.cross(_c4) < 0) {
          i = (i + 1) % e.length;
          continue;
        }
        var _d3 = false;
        var _iterator10 = babel_createForOfIteratorHelper(e);
        var _step10;
        try {
          for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
            var _n84 = _step10.value;
            if (_n84 != _t82 && _n84 != _s16 && _n84 != _a24 && this.isInTriangle(_n84, _t82, _s16, _a24)) {
              _d3 = true;
              break;
            }
          }
        } catch (err) {
          _iterator10.e(err);
        } finally {
          _iterator10.f();
        }
        if (_d3) {
          i = (i + 1) % e.length;
        } else {
          _o152.push(n(_t82), n(_s16), n(_a24));
          e.splice(_r6, 1);
        }
      }
      var _iterator11 = babel_createForOfIteratorHelper(e);
      var _step11;
      try {
        for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
          var _s17 = _step11.value;
          _o152.push(n(_s17));
        }
      } catch (err) {
        _iterator11.e(err);
      } finally {
        _iterator11.f();
      }
      return _o152;
    }
  }, {
    key: "isInTriangle",
    value: function isInTriangle(e, t, n, _o153) {
      var i = n.sub(t);
      var s = _o153.sub(t);
      var a = _o153.sub(n);
      var r = e.sub(t);
      var l = e.sub(n);
      return i.cross(s) >= 0 ^ i.cross(r) < 0 && i.cross(s) >= 0 ^ s.cross(r) >= 0 && a.cross(i) > 0 ^ a.cross(l) >= 0;
    }
  }, {
    key: "Random",
    value: function Random(e, t) {
      return Math.floor(Math.random() * (t - e + 1)) + e;
    }
  }, {
    key: "transitionColors",
    value: function transitionColors(e, t, n, _o154) {
      var i = [parseInt(e.slice(1, 3), 16), parseInt(e.slice(3, 5), 16), parseInt(e.slice(5, 7), 16)];
      var s = [parseInt(t.slice(1, 3), 16), parseInt(t.slice(3, 5), 16), parseInt(t.slice(5, 7), 16)];
      var a = [(s[0] - i[0]) / (n - 1), (s[1] - i[1]) / (n - 1), (s[2] - i[2]) / (n - 1)];
      var r = [];
      for (var _l6 = 0; _l6 < n; _l6++) {
        var _e93 = Math.round(i[0] + a[0] * _l6);
        var _t83 = Math.round(i[1] + a[1] * _l6);
        var _n85 = Math.round(i[2] + a[2] * _l6);
        var _o155 = new cc.Color(_e93, _t83, _n85);
        r.push(_o155);
      }
      this.applyColorTransition(r, n, _o154);
    }
  }, {
    key: "applyColorTransition",
    value: function applyColorTransition(e, t, n) {
      var _o156 = .1 / t;
      var i = 0;
      cc.tween(n).repeatForever(cc.tween().sequence(cc.tween().delay(_o156), cc.tween().call(function () {
        if (i < e.length) {
          n.color = e[i];
          i++;
        } else {
          n.color = e[e.length - 1];
        }
      }))).start();
    }
  }, {
    key: "compareVersions",
    value: function compareVersions(e, t) {
      var n = e.split(".").map(Number);
      var _o157 = t.split(".").map(Number);
      for (var _i38 = 0; _i38 < Math.max(n.length, _o157.length); _i38++) {
        var _e94 = n[_i38] || 0;
        var _t84 = _o157[_i38] || 0;
        if (_e94 < _t84) {
          return -1;
        }
        if (_e94 > _t84) {
          return 1;
        }
      }
      return 0;
    }
  }, {
    key: "goldFlyEffect",
    value: function goldFlyEffect() {
      var _this165 = this;
      return new Promise(function (e) {
        return cc__awaiter(_this165, undefined, undefined, /* */babel_regeneratorRuntime().mark(function _callee11() {
          var t;
          var n;
          var o;
          return babel_regeneratorRuntime().wrap(function _callee11$(_context12) {
            while (1) {
              switch (_context12.prev = _context12.next) {
                case 0:
                  t = $2WorldNodeMgr.default.Instance.getWorldTargetPosByName($2WorldNodeMgr.WorldTargetName.UITopBarMoney);
                  n = $2NodeManager.default.Instance.getTiliStartPoint();
                  o = n.convertToWorldSpaceAR(cc.Vec3.ZERO);
                  _context12.next = 3;
                  return n.addComponent($2GlobalTili.default).goldCoinFlying(o, t, n.parent);
                case 3:
                  e();
                case 4:
                case "end":
                  return _context12.stop();
              }
            }
          }, _callee11);
        }));
      });
    }
  }, {
    key: "random",
    value: function random(e, t) {
      return Math.floor(Math.random() * (t - e + 1)) + e;
    }
  }]);
}();
def_ccUtil._temppos = cc.v2(1, 0);
def_ccUtil._temppos1 = cc.v2(1, 0);
def_ccUtil._intersecRect = new cc.Rect();
def_ccUtil = _o140 = cc__decorate([ccp_ccclass], def_ccUtil);
exports.default = def_ccUtil;